<template>
  <div class="ptz-content" v-show="show" :style="`top: ${relativeY}px;left: ${relativeX}px`">
    <div class="ptz-menu">
      <div class="ptz-menu-item" @click="event('control')">手动控制</div>
      <div class="ptz-menu-item" @click="download">视频下载</div>
      <div class="ptz-menu-item" @click="playback">视频回放</div>
    </div>
  </div>
  <DownloadCard ref="downloadRef" :playbackUrl="props.playbackUrl" />
  <PlacyBack ref="playbackRef" @download="download" />
</template>

<script setup>
  import { ref } from 'vue';
  import DownloadCard from './download.vue';
  import PlacyBack from './playBack.vue';

  const props = defineProps({
    playbackUrl: {
      default: '',
    },
  });

  const emit = defineEmits(['menuEvent']);

  const downloadRef = ref();
  const playbackRef = ref();
  const show = ref(false);
  const relativeX = ref(0);
  const relativeY = ref(0);

  function event(type) {
    show.value = false;
    emit('menuEvent', type);
  }

  function open(coor) {
    relativeX.value = coor.relativeX;
    relativeY.value = coor.relativeY;
    show.value = true;
  }

  function download() {
    show.value = false;
    downloadRef.value.open();
  }

  function playback() {
    show.value = false;
    playbackRef.value.open(props.playbackUrl);
  }

  defineExpose({ open });
</script>

<style scoped lang="less">
  .ptz-content {
    position: absolute;
  }
  .ptz-menu {
    border-radius: 5px;
    overflow: hidden;
    .ptz-menu-item {
      height: 33px;
      line-height: 33px;
      font-size: 14px;
      background-color: #fff;
      color: #666;
      padding: 0 15px;
      border-bottom: 1px solid #ddd;
      user-select: none;
      cursor: pointer;
      &:hover {
        color: #000;
      }
    }
  }
</style>
